﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BlackScholesLib
{
    internal static class NormSDist_v1
    {
        private static double Norm(double z) //normal probability density function
        {
            double normsdistval = 1 / (Math.Sqrt(2 * Math.PI)) * Math.Exp(-Math.Pow(z, 2) / 2);
            return normsdistval;
        }

        public static double NormSDist(double x) //normal cumulative density function
        {
            const double b0 = 0.2316419;
            const double b1 = 0.319381530;
            const double b2 = -0.356563782;
            const double b3 = 1.781477937;
            const double b4 = -1.821255978;
            const double b5 = 1.330274429;
            double t = 1 / (1 + b0 * x);
            double sigma = 1 - Norm(x) * (b1 * t + b2 * Math.Pow(t, 2) + b3 * Math.Pow(t, 3)
            + b4 * Math.Pow(t, 4) + b5 * Math.Pow(t, 5));
            return sigma;
        }
    }
}
